const formatTime = time => {
  var date = new Date(time)
  const year = date.getFullYear()
  const month = date.getMonth() + 1
  const day = date.getDate()
  const hour = date.getHours()
  const minute = date.getMinutes()
  const second = date.getSeconds()
  return [year, month, day].map(formatNumber).join('/') + ' ' + [hour, minute].map(formatNumber).join(':')
}

const formatNumber = n => {
  n = n.toString()
  return n[1] ? n : '0' + n
}
var dateTime = function (time){
  var newTime = new Date(+new Date(time) + 8 * 3600 * 1000).toISOString().replace(/T/g, ' ').replace(/\.[\d]{3}Z/, '')
  return newTime
}
var dayTime = function (time) {
  var newTime = new Date(time)
  var yearTime =newTime.getFullYear();
  var monthTime = newTime.getMonth() + 1;
  var dayTime = newTime.getDate();
  function t(v) {
    return v < 10 ? '0'+v :  v
  }
  var timeString = yearTime+'-'+ t(monthTime) + '-' + t(dayTime) ;
  return timeString;
}
var monthTime =function(time){
  var newTime = new Date(time)
  var monthTime = newTime.getMonth()+1;
  var dayTime = newTime.getDate();
function t (v){
  return v < 10 ? '0' + v : v
}
  var timeString =t(monthTime) + '月' + t(dayTime)+ '日'
  return timeString;
}
module.exports = {
  formatTime: formatTime,
  dateTime: dateTime,
  dayTime: dayTime,
  monthTime: monthTime
}
